<?php

namespace app\api\model;

use app\admin\model\SystemConfig;
use think\facade\Db;
use think\Model;
use think\model\concern\SoftDelete;

/**
 * 积分签到
 */
class PointSign extends Model
{
    // protected static function base($query)
    // {
    //     $query->where('status',1);
    // }

    // protected $name='mall_goods';

    // 开启自动写入时间戳字段
    protected $auto_timestamp = 'false';

    // 设置json类型字段
	// protected $json = ['sf'];
 
      // 追加属性

      use SoftDelete;

      protected $deleteTime = 'delete_time';
      
      public function signIn($uid)
      {
          $systemPoint = SystemConfig::where('name', 'point_sign')->value('value');
          Db::startTrans();
          try {
            $this->save(['uid'=>$uid, 'point'=>$systemPoint, 'desc'=>'签到送积分']);
            User::where('id', $uid)->inc('integral', $systemPoint)->update();
            // 提交事务
            Db::commit();
          } catch (\Exception $e) {
            // 回滚事务
            Db::rollback();
            return false;
          }
          return true;
      }
}
